﻿using System;

namespace SharpSqlAnalyzer.pp.utils
{
	// Token: 0x020001F6 RID: 502
	public class SourceTokenSearcher
	{
		// Token: 0x06001192 RID: 4498 RVA: 0x003156BC File Offset: 0x003138BC
		public static int IndexOf(TSourceTokenList list, int startPos, int endPos, string text)
		{
			if (text == null)
			{
				return -1;
			}
			for (int i = startPos; i < endPos; i++)
			{
				if (i < 0 || i >= list.size())
				{
					return -1;
				}
				if (list.get(i).astext != null && list.get(i).astext.TrimEnd(new char[1]).Trim().Equals(text, StringComparison.OrdinalIgnoreCase))
				{
					return i;
				}
			}
			return -1;
		}

		// Token: 0x06001193 RID: 4499 RVA: 0x00315720 File Offset: 0x00313920
		public static int IndexOf(TSourceTokenList list, int startPos, int endPos, ETokenType type)
		{
			for (int i = startPos; i < endPos; i++)
			{
				if (i < 0 || i >= list.size())
				{
					return -1;
				}
				if (type == list.get(i).tokentype)
				{
					return i;
				}
			}
			return -1;
		}

		// Token: 0x06001194 RID: 4500 RVA: 0x0031575A File Offset: 0x0031395A
		public static int IndexOf(TSourceTokenList list, int startPos, string text)
		{
			return SourceTokenSearcher.IndexOf(list, startPos, list.size() - 1, text);
		}

		// Token: 0x06001195 RID: 4501 RVA: 0x0031576C File Offset: 0x0031396C
		public static TSourceToken backforwardSearch(TSourceToken token, int backsearchSize, string text)
		{
			int num = SourceTokenSearcher.LastIndexOf(token.container, token.posinlist - backsearchSize, token.posinlist, text);
			if (num == -1)
			{
				return null;
			}
			return token.container.get(num);
		}

		// Token: 0x06001196 RID: 4502 RVA: 0x003157A8 File Offset: 0x003139A8
		public static TSourceToken forwardSearch(TSourceToken token, int forwardSearchSize, string text)
		{
			int num = SourceTokenSearcher.IndexOf(token.container, token.posinlist, token.posinlist + forwardSearchSize, text);
			if (num == -1)
			{
				return null;
			}
			return token.container.get(num);
		}

		// Token: 0x06001197 RID: 4503 RVA: 0x003157E4 File Offset: 0x003139E4
		public static int LastIndexOf(TSourceTokenList list, int startPos, int endPos, string text)
		{
			if (text == null)
			{
				return -1;
			}
			if (startPos < 0)
			{
				startPos = 0;
			}
			if (endPos - 1 > list.size())
			{
				endPos = list.size();
			}
			for (int i = endPos - 1; i >= startPos; i--)
			{
				if (i < 0 || i >= list.size())
				{
					return -1;
				}
				if (list.get(i).astext != null && list.get(i).astext.TrimEnd(new char[1]).Trim().Equals(text, StringComparison.OrdinalIgnoreCase))
				{
					return i;
				}
			}
			return -1;
		}

		// Token: 0x06001198 RID: 4504 RVA: 0x00315863 File Offset: 0x00313A63
		public static int LastIndexOf(TSourceTokenList list, int endPos, string text)
		{
			return SourceTokenSearcher.LastIndexOf(list, 0, endPos, text);
		}

		// Token: 0x06001199 RID: 4505 RVA: 0x00315870 File Offset: 0x00313A70
		public static TSourceToken lastNotWhitespaceAndReturnToken(TSourceTokenList list, int startPos, int endPos)
		{
			for (int i = endPos - 1; i >= startPos; i--)
			{
				if (i < 0 || i >= list.size())
				{
					return null;
				}
				if (list.get(i).tokentype != ETokenType.ttwhitespace && list.get(i).tokentype != ETokenType.ttreturn && list.get(i).tokentype != ETokenType.ttsimplecomment && list.get(i).tokentype != ETokenType.ttbracketedcomment)
				{
					return list.get(i);
				}
			}
			return null;
		}

		// Token: 0x0600119A RID: 4506 RVA: 0x003158DF File Offset: 0x00313ADF
		public static TSourceToken lastNotWhitespaceAndReturnToken(TSourceTokenList list, int endPos)
		{
			return SourceTokenSearcher.lastNotWhitespaceAndReturnToken(list, 0, endPos);
		}

		// Token: 0x0600119B RID: 4507 RVA: 0x003158EC File Offset: 0x00313AEC
		public static TSourceToken lastSelectedNotWhitespaceAndReturnToken(TSourceTokenList list, int endPos, string text)
		{
			TSourceToken tsourceToken = SourceTokenSearcher.lastNotWhitespaceAndReturnToken(list, endPos);
			if (tsourceToken != null && tsourceToken.astext != null && tsourceToken.astext.TrimEnd(new char[1]).Trim().Equals(text, StringComparison.OrdinalIgnoreCase))
			{
				return tsourceToken;
			}
			return null;
		}

		// Token: 0x0600119C RID: 4508 RVA: 0x00315930 File Offset: 0x00313B30
		public static TSourceToken firstNotWhitespaceAndReturnToken(TSourceTokenList list, int startPos, int endPos)
		{
			for (int i = startPos; i < endPos; i++)
			{
				if (i < 0 || i >= list.size())
				{
					return null;
				}
				if (list.get(i).tokentype != ETokenType.ttwhitespace && list.get(i).tokentype != ETokenType.ttreturn && list.get(i).tokentype != ETokenType.ttsimplecomment && list.get(i).tokentype != ETokenType.ttbracketedcomment)
				{
					return list.get(i);
				}
			}
			return null;
		}

		// Token: 0x0600119D RID: 4509 RVA: 0x003159A0 File Offset: 0x00313BA0
		public static TSourceToken firstSelectNotWhitespaceAndReturnToken(TSourceTokenList list, int startPos, string text)
		{
			for (int i = startPos; i < list.size(); i++)
			{
				if (i >= 0 && i < list.size())
				{
					TSourceToken tsourceToken = list.get(i);
					if (tsourceToken.tokentype != ETokenType.ttwhitespace && tsourceToken.tokentype != ETokenType.ttreturn && list.get(i).tokentype != ETokenType.ttsimplecomment && list.get(i).tokentype != ETokenType.ttbracketedcomment)
					{
						if (tsourceToken.astext != null && tsourceToken.astext.TrimEnd(new char[1]).Trim().Equals(text, StringComparison.OrdinalIgnoreCase))
						{
							return tsourceToken;
						}
						return null;
					}
				}
			}
			return null;
		}

		// Token: 0x0600119E RID: 4510 RVA: 0x00315A2F File Offset: 0x00313C2F
		public static TSourceToken lastSelectedNotWhitespaceAndReturnToken(TSourceToken token, string text)
		{
			if (token == null)
			{
				return null;
			}
			return SourceTokenSearcher.lastSelectedNotWhitespaceAndReturnToken(token.container, token.posinlist, text);
		}

		// Token: 0x0600119F RID: 4511 RVA: 0x00315A48 File Offset: 0x00313C48
		public static bool isNewLineToken(TSourceToken token)
		{
			return token != null && token.tokentype == ETokenType.ttreturn;
		}

		// Token: 0x060011A0 RID: 4512 RVA: 0x00315A59 File Offset: 0x00313C59
		public static bool isSimpleComment(TSourceToken token)
		{
			return token != null && token.tokentype == ETokenType.ttsimplecomment;
		}

		// Token: 0x060011A1 RID: 4513 RVA: 0x00315A6C File Offset: 0x00313C6C
		public static TSourceToken backforwardSearchNotWhitespaceAndReturnToken(TSourceToken endToken, int backforwardSearchSize, string text)
		{
			TSourceToken tsourceToken = endToken;
			while (backforwardSearchSize > 0)
			{
				tsourceToken = SourceTokenSearcher.lastNotWhitespaceAndReturnToken(tsourceToken.container, tsourceToken.posinlist);
				if (tsourceToken != null && tsourceToken.astext != null && tsourceToken.astext.TrimEnd(new char[1]).Trim().Equals(text, StringComparison.OrdinalIgnoreCase))
				{
					return tsourceToken;
				}
				backforwardSearchSize--;
			}
			return null;
		}

		// Token: 0x060011A2 RID: 4514 RVA: 0x00315AC8 File Offset: 0x00313CC8
		public static TSourceToken lastSelectedToken(TSourceTokenList list, int startPos, int endPos, string text)
		{
			for (int i = endPos; i >= startPos; i--)
			{
				if (i < 0 || i >= list.size())
				{
					return null;
				}
				TSourceToken tsourceToken = list.get(i);
				if (tsourceToken.ToString().Equals(text, StringComparison.CurrentCultureIgnoreCase))
				{
					return tsourceToken;
				}
			}
			return null;
		}

		// Token: 0x060011A3 RID: 4515 RVA: 0x00315B0C File Offset: 0x00313D0C
		public static TSourceToken firstSelectedToken(TSourceTokenList list, int startPos, int endPos, string text)
		{
			for (int i = startPos; i <= endPos; i++)
			{
				if (i < 0 || i >= list.size())
				{
					return null;
				}
				TSourceToken tsourceToken = list.get(i);
				if (tsourceToken.ToString().Equals(text, StringComparison.CurrentCultureIgnoreCase))
				{
					return tsourceToken;
				}
			}
			return null;
		}
	}
}
